<?php

namespace App\Store\Validate\Goods;

use App\Common\Validate\BaseValidate;

/**
 * 商品调拨验证器
 */
class GoodsAllot extends BaseValidate
{
    //验证规则
    protected $rule = [];
    //自定义验证信息
    protected $message = [];

    public function __construct($doaction = 'add')
    {
        if ($doaction == 'add') {
            $this->rule = [
                'target_store_id'  => 'required',
                'goods_list' => 'required',
            ];
            $this->message = [
                'target_store_id.required'  => '目的门店未选择',
                'goods_list.required' => '商品列表不能为空'
            ];
        } elseif ($doaction == 'edit') {
            $this->rule = [
                'id'         => 'required',
                'goods_list' => 'required',
            ];
            $this->message = [
                'id.required'         => '父id不能为空',
                'goods_list.required' => '商品列表不能为空'
            ];
        } elseif ($doaction == 'del') {
            $this->rule = [
                'id' => 'required',
            ];
            $this->message = [
                'id.required' => 'id不能为空',
            ];
        } elseif ($doaction == 'getone') {
            $this->rule = [
                'type'=>'required|in:1,2,3',
            ];
            $this->message = [
                'type.required' => '类型未选择',
                'type.in'       => '类型无效',
            ];
        } elseif ($doaction == 'review') {
            $this->rule = [
                'type'   => 'required|in:1,2,3',
                'p_id'   => 'required',
                'id'     => 'required',
                'result' => 'required|in:1,2',
            ];
            $this->message = [
                'type.required'   => '类型未选择',
                'type.in'         => '类型无效',
                'p_id.required'   => '父id不能为空',
                'id.required'     => 'id不能为空',
                'result.required' => '操作结果不能为空',
                'result.in'       => '操作结果类型无效'
            ];
        }
    }
}
